//
// Created by root on 24-7-18.
//

#define IRQ0_FREQUENCE 100
#define INPUT_FREQUENCE 1193180
#define COUNTER_ER0_VALUE INPUT_FREQUENCE/IRQ0_FREQUENCE
#define COUNTER_ER0_PORT 0x40
#define COUNTER_ER0_NUM 0
#define COUNTER_ER0_MODE 2
#define COUNTER_ER0_READWRITE_LATCH 3
#define CONTROL_PORT 0x43
#include "../include/type.h"
#include "../include/print.h"
#include "../include/io.h"

void frequenceset(uint16 setvalue,uint8 whichcel,uint8 whichmode,uint8 whichlatch,uint8 wherecelport) {
    uint8 value = whichcel << 6 | whichlatch << 4 | whichmode << 1 | 0;
    printk("control port value is %d", value);
    rollup();
    outbyte(CONTROL_PORT, value);
    printk("init value is %d", setvalue);
    rollup();
    printk("init value low 8 is %d", (setvalue & 0x00ff));
    rollup();
    outbyte(wherecelport, setvalue & 0x00ff);
    printk("init value heigh 8 is %d", ((setvalue & 0xff00) >> 8));
    rollup();
    outbyte(wherecelport, (setvalue & 0xff00) >> 8);
}

void timerinit() {
    printk("start set timer frequence");
    rollup();
    frequenceset(COUNTER_ER0_VALUE,COUNTER_ER0_NUM,COUNTER_ER0_MODE,COUNTER_ER0_READWRITE_LATCH,COUNTER_ER0_PORT);
    printk("timer init done");
    rollup();
}
